<?php
   class File{
   	
   	/*
	 * $type：上传文件的分类
	 * $name:上传form表单file的name值
	 */
   	static function create_file($type,$name,$isupdate = false){
   		$file_path = DB::fetch_row("select * from `v_file_path` where `type`='{$type}'");
		$path       = $file_path['path'];
		$uploadFile = $_FILES[$name];
		$tmpName    = $uploadFile['tmp_name'];
		$fileType   = $uploadFile['type'];
		$fileError  = $uploadFile['error'];
		
		$file  =  array();
		$file['type']     =  $uploadFile['type'];
		$file['realname'] =  $path.time().strrchr($uploadFile['name'],".");
		$file['createtime'] = time();
		
		$ok = 0;
		switch($file['type']){
			case "text/plain":$ok=1;break;
	        case "application/msword":$ok=1;break;
	        case "application/vnd.ms-excel":$ok=1;break;
	        case "application/vnd.ms-powerpoint":$ok=1;break;
            case "image/jpg":$ok=1;break;
	        case "image/jpeg":$ok=1;break;
	        case "image/png":$ok=1;break;
	        case "image/pjpeg":$ok=1;break;
	        case "image/gif":$ok=1;break;
	        case "image/bmp":$ok=1;break;
	        case "image/x-png":$ok=1;
		}
		if(!$fileError&&$ok){
			move_uploaded_file($tmpName,$file['realname']);
			if(!$isupdate)
			    return DB::insert("v_file", $file);
			else
				return $file['realname'];
		}
		return 0;
   	}
	
	static function delete_file(){
		
	}
	
	static function update_file($type){
		
	}
	
   	
   }
   

?>